package com.spira;

import java.util.Date;
import java.util.GregorianCalendar;

import javax.xml.datatype.DatatypeConfigurationException;
import javax.xml.datatype.DatatypeConstants;
import javax.xml.datatype.DatatypeFactory;
import javax.xml.datatype.XMLGregorianCalendar;

public class XmlDate {

	public static String getActualDate(){
		try{
			
			return getXmlDate();
		}
		catch (DatatypeConfigurationException ex){
					
			throw new IllegalStateException("Could not get the actual date", ex);
		}
	}
	
	private static String getXmlDate() throws DatatypeConfigurationException{
		
		GregorianCalendar calendar = new GregorianCalendar();
		calendar.setTime(new Date());
		  
		DatatypeFactory datatypeFactory = DatatypeFactory.newInstance();
		XMLGregorianCalendar xmlCal = datatypeFactory.newXMLGregorianCalendar(calendar);
		xmlCal.setTimezone(DatatypeConstants.FIELD_UNDEFINED);
		  
		return xmlCal.toString();
	}
}
